<cfinclude template="/ecada/header.cfm">
	<cfquery name = "live" datasource = "exp" result="test">
		SELECT * 
		FROM experiment
		WHERE StatusID = (SELECT id
							FROM expstatus
							WHERE Status = 'live')
		AND (userid = #session.id#
			OR GroupID IN (SELECT GroupID
							FROM groupusers
							WHERE UserID = #session.id#)
			)
	</cfquery>
<cfoutput>
	Query Time: #test.executiontime#<br><br>
</cfoutput>
	<cfif #live.RecordCount# eq 0>
		<cfoutput>
			<h3>There are no live experiments!!</h3>
		</cfoutput>
	<cfelse>

<cfoutput>
<h2>Live experiments</h2>
	<cfloop query = "live">
		<table border="1">

			<cfquery datasource="exp" name="numparticipants">
					SELECT count(distinct participantid) as cnt
					FROM givesanswer,trial
					WHERE expid=#live.id# 
					AND	trial.id = givesanswer.trialid 
			</cfquery>
			
			<tr>
				<th colspan=2>Experiment Details</th>
			</tr>
			 <tr>
				<td colspan=2>#live.title#</td>
			</tr>
			<tr>
				<td colspan=2>#live.description#</td>
			</tr>
			<tr>
				<td>Maximum Participants </td>
				<td>#live.maxpart#</td>
			</tr>
			<tr>
				<td>Participants so far</td>
				<td>#numparticipants.cnt#</td>
			</tr>
			<tr>
				<td>start date: </td>
				<td>#live.startDate#</td>
			</tr>
			<tr>
				<td>end date: </td>
				<td>#live.endDate#</td>
			</tr>
			<tr>
				<td>Click to see more detail </td>
				<td>
					<a href="/ecada/viewexp/expdetail.cfm?id=#live.id#">Detail</a>
				</td>
			</tr>
			<tr>
				<td>Link for participants</td>
				<td>
					<a href="/ecada/ethics.cfm?id=#live.id#">#live.title#</a>
				</td>
			</tr>

			<tr>
				<td>To Edit your experiment or to stop it.</td>
				<td>
					<form method="post" action="experimentClose.cfm?id=#id#&close=1">
						<input type = "hidden" name = "#id#" value="#id#">
						<input type = "submit" value="Stop experiment" style="background-color:red;color:white;">
					</form>
				</td>
			</tr>
			<tr>
				<td>
					Link for participation
				</td>
				<td>
					<form method="post" action="emaillink.cfm?id=#id#">
						<input type = "hidden" name = "#id#" value="#id#">
						<input type = "submit" value="Email me the Participation link" style="background-color:##00ff00;">
					</form>
				</td>
			</tr>
		</table>
		<br>
		<br>
	</cfloop>

</cfoutput>
	
	</cfif>
<cfinclude template="/ecada/footer.cfm">
